# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=heplify-server
pkgver=1.59.7
pkgrel=6
pkgdesc="HEP Capture Server & Switch in Go"
url="http://sipcapture.io"
arch="all !riscv64 !ppc64le !loongarch64" # FTBFS
license="AGPL-3.0-or-later"
makedepends="go"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
options="net"
source="$pkgname-$pkgver.tar.gz::https://github.com/sipcapture/heplify-server/archive/refs/tags/v$pkgver.tar.gz
	$pkgname.initd
	"

case $CARCH in
	ppc64le|riscv64|loongarch64)
		makedepends="$makedepends lua5.1-dev"
		export GOFLAGS="$GOFLAGS -tags=llua"
		;;
	*)
		makedepends="$makedepends luajit-dev"
		;;
esac

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

export GOFLAGS="$GOFLAGS -modcacherw"

prepare() {
	default_prepare
	go mod download

	case $CARCH in
		armhf|armv7|x86|s390x|riscv64)
			# -race is not supported on these arches
			sed -i '/go test/s/-race//' Makefile
	esac
}

build() {
	make all
}

check() {
	# is not supported when testing with -race
	export GOFLAGS="${GOFLAGS/-buildmode=pie}"

	make test
}

package() {
	install -D -m755 heplify-server "$pkgdir"/usr/bin/heplify-server
	install -D -m644 example/homer7_config/heplify-server.toml \
		"$pkgdir"/etc/heplify-server/heplify-server.toml
	install -D -m755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
}

sha512sums="
3da594d16977ac967d2c52316f5634fbfb0a7464e44426eb1c8e55d0a47a3a4eea28964f12c53f4ac33deb88476816049544cf95973762ba99554ef368adea39  heplify-server-1.59.7.tar.gz
f090147fa00fa3c12bce3dd7dffbe97fe0eb5ab61cfccac996921ea36c957ffc55ce53f45e4d1f1b8e0bcc7b4ac7eb3bf362ab6d65b46f2619336d3c18197a11  heplify-server.initd
"
